<?php
/**
 * Página principal
 * @package default
 * @author Thiago Segato Antunes
 * @version 2.0
 * @copyright atitudeweb
 * @license http://opensource.org/licenses/gpl-3.0.html GPL General Public License
*/

define('EXEC', 1);
define('ATITUDE_BASE', dirname(__FILE__));
define('DS', DIRECTORY_SEPARATOR);
require_once(ATITUDE_BASE.DS.'includes'.DS.'framework.php');

//Verificando o logout do sistema
if(@$_GET['logout']){
	$auth->logout();
	$user = null;
}

ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php echo Config::SYSTEM; ?></title>
	<link type="text/css" href="assets/css/framework.css" rel="stylesheet" />
	<link type="text/css" href="assets/css/theme-default/jquery-ui-1.10.0.custom.min.css" rel="stylesheet" />
	<link rel="shortcut icon" href="assets/assets/favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" href="assets/dist/css/bootstrap.min.css">
	<link rel="stylesheet" href="assets/dist/css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.css">
	<script type="text/javascript" src="assets/js/jquery-lastest.min.js"></script>
	<script type="text/javascript" src="assets/js/jquery-ui-1.10.0.custom.min.js"></script>
	<script type="text/javascript" src="assets/dist/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="assets/js/jquery.datatables.min.js"></script>
	<script type="text/javascript" src="assets/js/framework.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap3-typeahead.min.js"></script>
	<script type="text/javascript" src="assets/js/moment-2.4.0.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap-datetimepicker.js"></script>
	<script type="text/javascript" src="assets/js/locales/bootstrap-datetimepicker.pt-BR.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap.touchspin.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap-filestyle.min.js"></script>
	<script type="text/javascript" src="assets/js/jscolor.js"></script>
	<atitudeweb:include type="head" />
</head>
<body>
	<div id="corpo">
		<?php
		if(!$user){
			include('includes/login.php');
		}
		else{
			include('includes/header.php');
			echo '<div id="conteudo">';
			if(!@$_GET['page']){
				include('includes/home.php');
			}
			else{
				if(file_exists('modules/'.$_GET['page'].'.php')){
					include('modules/'.$_GET['page'].'.php');
				}
				else{
					echo 'Módulo não encontrado: <b>'.'modules/'.$_GET['page'].'.php</b>';
				}
			}
			echo '</div>';
			include('includes/footer.php');
		}
		?>
	</div>
</body>
</html>
<?php
	$data = ob_get_contents();
	ob_end_clean();
	$matches = array();
	if(preg_match_all('#<atitudeweb:include\ type="([^"]+)" (.*)\/>#iU', $data, $matches)){
		if($matches[1][0] == 'head'){
			$buffer = '';
			for($i=0;$i<count(Controller::$head);$i++){
				$buffer .= Controller::$head[$i]."\n";
			}
			$data = str_replace($matches[0][0], $buffer, $data);
		}
	}
	echo $data;
	if(@$_POST['info']){
		Util::notice($_POST['title'], $_POST['text'], $_POST['type']);
	}
?>